package first.niuke.simple;

/**
 * @ClassName NC32
 * @description:
 * @author: 荣燊
 * @create: 2021-06-10 11:14
 **/
public class NC32 {
    // 求平方根
    // 奇数相加法，最后求奇数的个数

    /**
     * 例: 9 = 1 + 3 + 5;
     * 16 = 1 + 3 + 5 + 7;
     * @param x
     * @return
     */
    public int sqrt (int x) {
        // write code here
        int tmp = 1, num = 0;
        while (x >= 0) {
            x -= tmp;
            tmp += 2;
            num++;
        }
        return num-1;
    }
}
